package com.sjy.framework;

import java.text.MessageFormat;

public class CodeNodeErrorTemplate {

    private String code;

    private String messageTpl;

    private String viewTpl;

    public CodeNodeErrorTemplate(String code, String messageTpl, String viewTpl) {
        this.code = code;
        this.messageTpl = messageTpl;
        this.viewTpl = viewTpl;
    }

    public CodeNodeError getError(Object... args){
        String message;
        String view;

        try{
            message = MessageFormat.format(this.messageTpl,args);
            view = MessageFormat.format(this.viewTpl,args);
        }catch (Exception e){
            return SystemErrorEnum.SYSTEM_ERROR.getError(new Object[0]);
        }
        return new CodeNodeError(this.code,message,view);
    }
}
